Optimize TerminalCommandDisplay visual wrapping with early-exit preview - #1224
Optimize TerminalCommandDisplay visual wrapping with early-exit preview#1224nordicnode wants to merge 2 commits into
Conversation
|
Nice motivation and benchmarking — early-exiting the wrap loop once However, there's a real correctness bug in the collapsed-state loop: if (line.length === 0) {
linesProcessed++
continue
}This skips blank lines entirely instead of treating them as one visual line (as Separately, the off-screen line-count estimate ( Fix the blank-line handling (count it as one line, don't skip it) and either compute the hidden count from the real wrapper for the first chunk past |
|
Thanks for catching this @codebuff-team! Both points have been resolved in the latest commit:
|
Summary
cli/src/components/terminal-command-display.tsx, optimize<TerminalCommandDisplay />to compute visual line wrapping on-demand and exit early once the preview limit (maxLines) is reached.!isExpanded), breaks out of line wrapping as soon asmaxLinesvisual lines are gathered, evaluating only the lines needed for the preview rather than running the regex word-splitter across all lines.displayLines.push('')), off-screen visual line counts, and expanded line checks, ensuring 100% layout parity for command outputs with interstitial blank lines (such as build logs, test summaries, andgit log --stat).excessInProcessedLine = wrapped.length - i).getLastNVisualLineson the first 50 off-screen lines, and uses a fast character-width estimateMath.max(1, Math.ceil(line.length / width))for lines beyond 50. This provides exact line counts on common command outputs while preventing CPU stalls on massive (e.g. 10,000-line) logs.isExpanded), full output is directly passed to the OpenTUI text renderer without intermediate wrapping allocations, checkinghasMoreLinesin O(1).cli/src/components/__tests__/terminal-command-display.test.tsx, added component tests verifying:maxVisibleLineswith "Show more" button.Test plan
bun test --config=/dev/null src/components/__tests__/terminal-command-display.test.tsx(6 passed, 0 failed)bun test --config=/dev/null src/components/tools/__tests__/run-terminal-command.test.ts(14 passed, 0 failed)bun run --cwd cli typecheck(0 errors)bun freebuff/cli/build.ts 0.0.0-ci(successful binary build)bun cli/scripts/smoke-binary.ts cli/bin/freebuff(OK)bun x prettier --check cli/src/components/terminal-command-display.tsx cli/src/components/__tests__/terminal-command-display.test.tsx(All matched files use Prettier code style)